import router from '@/router'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css' // 引入进度条样式
import useToken from '@/stores/token.js'
const whiteList = ['/login', '/404']
router.beforeEach((to, from, next) => {
  nprogress.start()
  const { token } = useToken()
  if (token) {
    // 有token的情况下
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
router.afterEach(() => {
  nprogress.done()
})
